package com.artisan.web.action;

import com.artisan.commonweb.result.ActionResult;
import com.artisan.medium.admin.service.AddressInfoService;
import com.artisan.model.AddressInfos;
import com.artisan.model.BusinessType;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by szw on 2017/7/8.
 */
@Controller
@RequestMapping("/admin/addressInfo/")
public class AddressInfoController {

	private Logger log = LogManager.getLogger(AddressInfoController.class);

	@Autowired
	private AddressInfoService addressInfoService;

	/**
	 * 根据pid查询下拉框的省市区
	 * @param pid
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "init_address",method = RequestMethod.GET)
	public ActionResult initAddressByPid(@RequestParam(defaultValue = "0") String pid) {
		ActionResult actionResult = new ActionResult();
		try {
			List<AddressInfos> addressInfos = addressInfoService.getAddressInfoByPid(pid);
			actionResult.setCode(200);
			actionResult.setData(addressInfos);
		}catch (Exception e){
			actionResult.setCode(400);
			actionResult.setHint(e.getMessage());
		}
		return actionResult;
	}
}
